<?php

/**
 * 夏日葵电商系统
 * http://www.xiarikui.com
 */

namespace App\Controller;

use App\Model\QuestionModel;
use App\Model\AnswerModel;
use App\Model\UserModel;

class IndexController extends MobileBaseController {

    public function lists()
    {
        if(!$this->user_id){
            jsonReturn();
        }
        $questionModel = new QuestionModel();
        $state = I('post.state');
        $page = I('post.page');
        $limit = I('post.limit');

        $count = $questionModel->getList($state,$page,$limit,1);
        $lists = $questionModel->getList($state,$page,$limit,0);

        $return['data'] = $lists;
        $return['page'] = $page;
        $return['total'] = $count;
        jsonReturn($return);
    }

    /*
    * 回答详情
    */
    public function detail(){
        if(!$this->user_id){
            jsonReturn();
        }
        $questionModel = new QuestionModel();
        $q_id = I('post.question_id');
        $find = $questionModel->getQuestionByIdWithAnswer($q_id);

        $arr['additional'] = $find['desc'];
        $arr['problem'] = $find['title'];
        //$arr['price_view'] = $find['open_reward'];
        $arr['price'] = $find['reward_money'];
        $arr['asked_head'] = $find['head_pic'];
        $arr['asked_nickname'] = $find['username'];
        $arr['browse_num'] = $find['read_num'];
        $arr['class_name'] = $find['cats_name'];
        $arr['endtime'] = $find['stop_time'];
        $arr['question_time'] = $find['add_time'];
        $arr['state'] = $find['answer_status'] == 2 ? 1 : 0;
        $arr['state_desc'] = $find['answer_status_desc'];
        if($find['answer_arr']){
            $arr['respond_content'] = $find['answer_arr']['content'];
            //$arr['money_view'] = $find['answer_arr']['charge_view'];
            $arr['money'] = $find['answer_arr']['charge_money'];
            $arr['adoption_num'] = $find['answer_arr']['adoption_num'];
            $arr['answer_time'] = $find['answer_arr']['add_time'];
        }
        jsonReturn($arr);
    }

    public function answer(){
        if(!$this->user_id){
            jsonReturn();
        }
        $post = I('post.');
        $answerModel = new AnswerModel();
        $res = $answerModel->answer($post);
        jsonReturn($res['status'] ? true : false ,$res['msg']);
    }



    /**
     * 获取地区列表
     */
    public function area_list() {
        $userModel = new UserModel();
        $lists = $userModel->getAreaList();
        jsonReturn(array('data' => $lists));
    }


}
